package com.wdc.hashtable;

import java.util.Arrays;

public class insertSort {
    public static void sort(int[] a) {
        for (int low = 1; low < a.length; low++) {
            int t = a[low];
            int i = low - 1;
            //找出待插入位置，空出来
            while ( i >= 0 && t < a[i]){
                a[i+1] = a[i];
                i--;
            }
            //找到了
            if (i != low -1){
                a[i+1] = t;
            }
        }

    }

    public static void main(String[] args) {
        int[] a ={2,1,7,4,9,4,99};
        sort(a);
        System.out.println(Arrays.toString(a));
    }
}
